# include <stdio.h>
# include <stdlib.h>
# include <sys/types.h>
# include <sys/socket.h>
# include <arpa/inet.h>
#include <string>

# include "proto.h"



int main (int argc, char *argv []){
    int sd;
    struct sockaddr_in  raddr; 
    struct msg_st sbuf;
    socklen_t raddr_len;
    char ipstr[IPSTRSIZE];

    if(argv < 2){
        fprintf (stderr, "Usage....\n"); 
        exit(1);
    }



    sd = socket (AF_INET, SOCK_DGRAM, 0/*IPPROTO_UDP*/) ;     //创建socket  AF_INET域 报式 0代表默认 
    if(sd < 0 ){
        perror("socket ()");
        exit(1);
    }
    //bind()     //发送端可以省略绑定 
    strcpy (sbuf.name, "Alan");     //组织数据  sbuf 是结构体，不能用 =，  直接拷贝
    sbuf.math = htonl(rand ()%100); 
    sbuf.chinese = htonl(rand ()%100);
    raddr.sin_family = AF_INET; 
    raddr.sin_port = htons (atoi(RCVPORT)); 
    inet_pton (AF_INET, argv [1], & raddr. sin_addr);
    if(sendto(sd, &sbuf, sizeof(sbuf), 0,(void *)&raddr, sizeof(raddr))<0 ) {  //发送数据
        perror("sendto()");
        exit (1);
    }         
    puts ("OK!");
    close (sd);
    exit(0);

}
